package com.dhcc.bpm.common.utils;

import org.springblade.core.mp.base.BaseEntity;
import org.springblade.core.secure.BladeUser;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.Func;

import java.util.Date;

/**
 * @ClassName: PublicFieldUtils.java
 * @author: 陈泽
 * @version: 1.0.0
 * @Description:
 * @createTime: 2019年12月10日 11:47:00
 */
public class PublicFieldUtils {

    public static  <T extends BaseEntity>  T setPublicField(T entity){
        BladeUser user = AuthUtil.getUser();
        if (user != null) {
            entity.setCreateUser(user.getUserId());
            entity.setCreateDept((Long) Func.toLongList(user.getDeptId()).iterator().next());
            entity.setUpdateUser(user.getUserId());
        }

        Date now = DateUtil.now();
        entity.setCreateTime(now);
        entity.setUpdateTime(now);
        if (entity.getStatus() == null) {
            entity.setStatus(1);
        }

        entity.setIsDeleted(0);
        return entity;

    }
}
